# -*- coding: utf-8 -*-
# @Time : 2023/9/27 11:59
# @Author : ZH
# @File : 1333.py
# @Software: PyCharm
from typing import List


class Solution:
    def __init__(self):
        self.veganFriendly = []
        self.un_veganFriendly = []


    def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> \
    List[int]:
        self.vegan(restaurants)
        true_vegan = self.veganFriendly if veganFriendly else restaurants
        # print(true_vegan)
        if not true_vegan:
            return []
        true_ = []
        for i in true_vegan:
            if i[-2] <= maxPrice and i[-1] <= maxDistance:
                true_.append(i)
        if not true_:
            return []
        true_ = [dict(id=i[0], rating=i[1]) for i in true_]
        return [i.get('id') for i in sorted(true_, key=lambda x: (x["rating"], x['id']), reverse=True)]




    def vegan(self, restaurants: List[List[int]]):
        for i in restaurants:
            if i[2]:
                self.veganFriendly.append(i)


if __name__ == '__main__':
    so = Solution()
    z = so.filterRestaurants(
        restaurants=[[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]],
        veganFriendly=1,
        maxPrice=50,
        maxDistance=10
    )
    print(z)
